package arrAndstr;

public class T26 {


    public static int removeDuplicates(int[] nums) {
        // 直接建立新数组
        int len = nums.length;
        int[] newArray = new int[len];
        fillZero(newArray);
        newArray[0] = nums[0];

        int indexNow = 1;
        int count = 1;
        for(int i=1; i<len; i++) {
            if(nums[i] == nums[i-1]) {
                continue;
            } else {
                newArray[indexNow++] = nums[i];
                count++;
            }
        }

        copyArray(newArray, nums);

        return count;
    }
    public static void fillZero(int[] array) {
        for(int i=0; i<array.length; i++) {
            array[i] = 0;
        }
    }
    public static void copyArray(int[] source, int[] dest) {
        for(int i=0; i<source.length; i++) {
            dest[i] = source[i];
        }
    }
}
